const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({
  data: {
    userInfo:'',
    kfconcatnums:'',
    myDataCountdata:"",
    navHeight:'',
  },
  onLoad: function (options) {
    this.setData({
      navHeight: app.globalData.navHeight
    })
  },
  onShow: function () {
    // if (!wx.getStorageSync('logintoken')) {
    //   app.ToLogin(true)
    // }else{
    //   this.info()
    //   this.myDataCount()
    // }
    this.kfconcat()
  },
  info(){
    Controller.info().then(res=>{
      if(res.data.baseData){
        this.setData({
          userInfo:res.data.baseData
        })
      }
    })
  },
  myDataCount(){
    Controller.myDataCount().then(res=>{
      if(res.data.baseData){
        this.setData({
          myDataCountdata:res.data.baseData,
        })
      }
    })
  },
  kfconcat(){
    Controller.appinfo({key:"key-phone"}).then(res=>{
      if(res.data.baseData){
        this.setData({
          kfconcatnums:res.data.baseData.content
        })
      }
    })
  },
  golink(e){
    // if (!wx.getStorageSync('logintoken')) {
    //   app.ToLogin(true)
    //   return
    // }
    var url=e.currentTarget.dataset.url;
    wx.navigateTo({
      url: url
    })
  },
  concat(e){

    wx.showActionSheet({
      itemList: [e.currentTarget.dataset.tel,'呼叫'],
      success:function(res){
        if(res.tapIndex==1){
          wx.makePhoneCall({
            phoneNumber: e.currentTarget.dataset.tel,
          })
        }
      }
    })
  },
  onShareAppMessage: function (e) {
    let userInfo=wx.getStorageSync('userInfo') || '';
    let path=app.getCurrentPageUrl()
    if(path.indexOf('?')!=-1){
      path=path+"&parentid="+userInfo.id
    }else{
      path=path+"?parentid="+userInfo.id
    }
    console.log(path)
    let obj = {
      path,
      success: function (res) {
        
      },
      fail(err) {
        
      }
    }
    return obj
  },
  onShareTimeline: function(res){
    let userInfo=wx.getStorageSync('userInfo') || '';
    let path=app.getCurrentPageUrl()
    if(path.indexOf('?')!=-1){
      path=path+"&parentid="+userInfo.id
    }else{
      path=path+"?parentid="+userInfo.id
    }
    let obj = {
      path,
      success: function (res) {
        
      },
      fail(err) {
       
      }
    }
    return obj
  },
})